package cn.jdy.plugins.service;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.jdy.framework.db.hibernate.BaseDao;
import cn.jdy.framework.util.StringUtil;
import cn.jdy.platform.service.ConfService;
import cn.jdy.plugins.entity.Maidjqfhcdb;

/**
 * @title 运营商分钱抽成记录后台操作
 * @author jga
 * @since 2018-10-11
 */
@Service
public class MaidjqfhcdbService extends BaseDao<Maidjqfhcdb>{

	@Autowired
	private ConfService confService;
	
	/**
	 * 按条件查询
	 * @param sp
	 * 
	 * @return
	 */
	public List<Maidjqfhcdb> query(Maidjqfhcdb sp){
		if(sp==null) return super.findAll();
		if(sp.getiDisplayLength() > 0){
	     return super.find(createFilter(sp),sp.getiDisplayStart(),sp.getiDisplayLength());
			}
		return super.find(createFilter(sp));
	}
	 public List<Maidjqfhcdb> querypage(Maidjqfhcdb sp){
	       return super.find(createFilter(sp),sp.getPageNo(),18);
	  }
	public Long count(Maidjqfhcdb sp){
		return super.count(createFilter(sp));
	}
	/**
	 * 拼装条件
	 * @param sp
	 * 
	 * @return
	 */
	private DetachedCriteria createFilter(Maidjqfhcdb sp){
		DetachedCriteria dc = DetachedCriteria.forClass(entityClass);
		if(!StringUtil.isNullOrEmpty(sp.getProductxid())) {
	        dc.add(Restrictions.like("productxid", sp.getProductxid()));
		} 
		
		if(!StringUtil.isNullOrEmpty(sp.getProductxid())) {
	        dc.add(Restrictions.eq("mch_id", sp.getMch_id()));
		} 
		
	
		
		if(!StringUtil.isNullOrEmpty(sp.getCreateTime())) {
	        dc.add(Restrictions.like("createTime", sp.getCreateTime()));
	 
		} 
		dc.addOrder(Order.desc("createTime"));
			return dc;
	}
	

}
